package com.pattern.singleton;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ContainerSingleton {
    public ContainerSingleton() {
    }

    private static Map<String,Object> ioc=new ConcurrentHashMap<>();

    public static  Object getBean(String className){

        if(!ioc.containsKey(className)){
            Object obj=null;
            try{
                obj=Class.forName(className).newInstance();
                ioc.put(className,obj);
            }catch (Exception e){
                e.printStackTrace();
            }
            return obj;
        }else{
            return ioc.get(className);
        }
    }
}
